package com.fruitshop.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fruitshop.entity.Product;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 商品Mapper接口
 */
@Mapper
public interface ProductMapper extends BaseMapper<Product> {
    
    /**
     * 根据分类ID查询商品列表
     */
    @Select("SELECT * FROM product WHERE category_id = #{categoryId} AND status = 1 AND deleted = 0")
    List<Product> findByCategoryId(@Param("categoryId") Integer categoryId);
    
    /**
     * 根据关键词搜索商品
     */
    @Select("SELECT * FROM product WHERE (title LIKE CONCAT('%', #{keyword}, '%') OR description LIKE CONCAT('%', #{keyword}, '%')) AND status = 1 AND deleted = 0")
    List<Product> searchByKeyword(@Param("keyword") String keyword);
    
    /**
     * 获取热销商品列表
     */
    @Select("SELECT * FROM product WHERE status = 1 AND deleted = 0 ORDER BY number DESC LIMIT #{limit}")
    List<Product> findHotProducts(@Param("limit") Integer limit);
} 